-
Notifications
You must be signed in to change notification settings - Fork 860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement reading of simple key-value Logstash JSON Marker attributes #12513
base: main
Are you sure you want to change the base?
Conversation
087cdd9
to
6f0d31f
Compare
Ah, Muzzle, I was afraid of that. I have no idea on what is wrong. |
About CI failing, you can refer to https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/CONTRIBUTING.md#troubleshooting-pr-build-failures |
6f0d31f
to
4129983
Compare
Thanks, hopefully fixed Muzzle. |
Marking as draft:
I will finish this later next week. |
click the "Ready for review" button when you are ready for it to be reviewed, thanks! |
4129983
to
fa99c59
Compare
fa99c59
to
c4b7dd5
Compare
Supported are MapEntriesAppendingMarker and SingleFieldAppendingMarker (i.e. ObjectAppendingMarker and RawJsonAppendingMarker) only. The attribute value is sent either as boolean, long, double or String or typed-array with respective values. The generic types (Object[], Collection) is converted to String array with values converted with String.valueOf() method. Typically the Logstash markers are added to logs via Markers.append(), Markers.appendEntries(), Markers.appendArray() and Markers.appendRaw() methods. Signed-off-by: Oldřich Jedlička <[email protected]>
c4b7dd5
to
fea5c4d
Compare
Updated, rebased, ready for review. It looks like the build errors are unrelated (Lettuce). |
try { | ||
Class.forName("net.logstash.logback.marker.LogstashMarker"); | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
|
||
try { | ||
Class.forName("net.logstash.logback.marker.SingleFieldAppendingMarker"); | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
|
||
try { | ||
Class.forName("net.logstash.logback.marker.MapEntriesAppendingMarker"); | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could have all Class.forName
calls inside the same try-catch block
@@ -60,6 +70,8 @@ public final class LoggingEventMapper { | |||
private static final AttributeKey<List<String>> LOG_BODY_PARAMETERS = | |||
AttributeKey.stringArrayKey("log.body.parameters"); | |||
|
|||
private static final Cache<Class<?>, Field> valueField = Cache.bounded(20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps ClassValue
would serve better for caching the fields?
} | ||
} | ||
|
||
private static void captureKeyValueAttribute( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this method isn't only used for key value attributes any more maybe it should be renamed
} | ||
} | ||
|
||
private static <T> void captureKeyArrayValueAttribute( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be easier to write the converted values to a list.
private static <T> void captureKeyArrayValueAttribute(
AttributesBuilder attributes,
AttributeKey<List<T>> key,
Object array,
Function<Object, T> extractor) {
List<T> list = new ArrayList<>();
int length = java.lang.reflect.Array.getLength(array);
for (int i = 0; i < length; i++) {
Object value = (T) java.lang.reflect.Array.get(array, i);
if (value != null) {
list.add(extractor.apply(value));
}
}
// empty lists are not serialized
if (!list.isEmpty()) {
attributes.put(key, list);
}
}
} else if (value instanceof Double || value instanceof Float) { | ||
attributes.put(keyStr, ((Number) value).doubleValue()); | ||
} else if (value.getClass().isArray()) { | ||
if (value instanceof boolean[] || value instanceof Boolean[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a unit test for this method to ensure that all the array variations are tested.
Supported are
MapEntriesAppendingMarker
andSingleFieldAppendingMarker
(i.e.ObjectAppendingMarker
andRawJsonAppendingMarker
) only. The attribute value is always a string retrieved by a call totoString()
method.Typically the Logstash markers are added to logs via
Markers.append()
andMarkers.appendEntries()
methods.Closes #12573